package base_grammar

import "fmt"

func Function() {
	fmt.Printf("sum(2, 5): %v\n", func_sum(2, 5))
	name, age := func_f1()
	fmt.Printf("name: %v\n", name)
	fmt.Printf("age: %v\n", age)
	name, age = func_f2()
	fmt.Printf("name: %v\n", name)
	fmt.Printf("age: %v\n", age)

	name2, _ := func_f3()
	fmt.Printf("name2: %v\n", name2)

	x := 100
	// copy  值传递  不会改变原来的值
	func_f4(x)
	fmt.Printf("x: %v\n", x)

	// 指针类型的（map、slice、interface、channel） 修改会影响原先的值
	a := []int{1, 2, 3}
	func_f5(a)
	fmt.Printf("a: %v\n", a)
	// 可变长参数
	func_f6("zhoujl", 111, 222, 333, 444)
}

func func_f6(name string, age ...int) {
	fmt.Printf("name: %v\n", name)
	for _, v := range age {
		fmt.Printf("v: %v\n", v)
	}
}

func func_f5(arr []int) {
	arr[0] = 100
}

func func_f4(a int) {
	a = 400
}

func func_f3() (name string, age int) {
	n := "zhoujl"
	a := 28
	return n, a
}

func func_f2() (name string, age int) {
	name = "zhoujl"
	age = 28
	return
}

func func_f1() (name string, age int) {
	return "zhoujl", 28
}

func func_sum(a int, b int) (ret int) {
	ret = a + b
	return ret
}

func func_sum2(a int, b int) int {
	ret := a + b
	// return a+b
	return ret
}
